#coding=utf-8

from selenium import webdriver
from appium import webdriver
from time import sleep
from selenium.common.exceptions import WebDriverException
import os
from nav_plugin_op import nav_plugin_factory
from Public import BasePage
from Tool.usefulTools import userfulToolsFactory
from Public.BasePage import element_Oprate
from Public.BasePage import BasicAction
from TestCase.loginEgovaMobile import login_factory
from Public import BaseConstant
import TestCase
from Public import CaseExcelOperate
import settings

navOpenFactory = nav_plugin_factory()
userfulTool = userfulToolsFactory()
element_oprate_instance = element_Oprate()
element_find_instance = BasicAction()
baseInstance = BasePage.Base()
loginDevices = login_factory()
Today_tips_Paramter_instances = BaseConstant.Today_tips_Paramter
caseExcelOp = CaseExcelOperate.excel_Operate()

# nav_name = "工作"
# plugin_name = "今日提示"
nav_name = ["导航栏工作",'xpath',"//android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.FrameLayout/android.widget.RadioButton"]
plugin_name = ["插件列表-今日提示",'name','今日提示']
actionbar_id = "cn.com.egova.todaytip:id/actionbar_menuview_image"
delecte_tip_id = "cn.com.egova.todaytip:id/actionbar_menu_list_item"

user_info = caseExcelOp.get_userInfo(settings.test_case_file,'Login_eGovaMobile')

class today_tip_factory():

	def login_egova(self):
		print 'login'
		login_factory.login_system(loginDevices,baseInstance.driver,user_info[0],user_info[1],settings.pic_file_path)

	def open_todaytip_plug(self,driver,file_path):
		try:
			# 点击工作的导航，打开工作列表
			element_oprate_instance.element_click(nav_name,file_path)
			# 点击"今日提示"的插件，打开插件
			element_oprate_instance.element_click(plugin_name,file_path)
			#等待今日提示页面内容进行加载，加载完成之后进行页面确认并界面
			element_oprate_instance.element_save_pic(file_path, 'open_todaytip_plug_successful')

		except WebDriverException,error:
			print error
			element_oprate_instance.element_save_pic(file_path, 'open_todaytip_plug_fail')
			raise

	def scan_tips(self,driver,file_path):
		print u'进行 今日提示 内容获取点击查看'
		try:
			#获取到今日提示第一条的标题
			today_tips_title_list = element_find_instance.find_element(Today_tips_Paramter_instances.today_tips_title,settings.pic_file_path).get_attribute('text')
			element_oprate_instance.element_click(Today_tips_Paramter_instances.today_tips_title,settings.pic_file_path)
			sleep(5)
			#获取详情页面的标题
			today_tips_title_detail = element_find_instance.find_element(Today_tips_Paramter_instances.today_tips_title,settings.pic_file_path).get_attribute('text')
			#两个标题进行比较
			if today_tips_title_list == today_tips_title_detail:
				print u'今日提示内容打开成功'
				element_oprate_instance.element_save_pic(file_path, 'scan_Todaytips_successful')
			else:
				print u'今日提示内容打开失败'
				element_oprate_instance.element_save_pic(file_path, 'scan_Todaytips_failed')
				raise

		except WebDriverException,error:
			print error
			print u'未获取到今日提示的内容，抛出异常'
			element_oprate_instance.element_save_pic(file_path, 'scan_tips_fail')
			raise


if __name__ == '__main__':
	print u'今日提示'